<?php

namespace Crm\Controller;

/**
 * 权限控制器
 *
 * @author SoChishun <14507247@qq.com>
 * @version 1.0
 * @since 1.0.0 <2015-3-26> SoChishun Added.
 */
class PermissionController extends AppbaseController {

    public function assert_upr($rule = '') {
        
    }

    /**
     * index操作
     * @since 1.0.0 <2015-3-26> by SoChishun Added.
     */
    public function index() {
        $this->display();
    }

    /**
     * 编辑角色权限操作
     * @param int $id 角色编号
     */
    public function role_rules($id) {
        $this->base_common_add_visit_history('编辑角色权限');
        $this->assign('rule_list', D('Permission')->get_main_nav(-1));
        $this->assign('rule', $permissions = M('tuser_role')->where(array('id' => $id))->getField('permission_rule'));
        $this->assign('id',$id);
        $this->display();
    }

    /**
     * 保存角色权限操作
     */
    public function role_rules_save() {
        $ids = I('ids');
        $id = I('id');
        if (!$id) {
            $this->error('参数有误');
        }
        $msg = D('Role')->update_permissions($id, is_array($ids) ? implode(',', $ids) : $ids);
        $this->base_redirect_return($msg, U('Permission/role_rules', 'toastr=1&id=' . $id),'role_rules');
    }

}
